package csu.web.mypetstore.web.servlet;

import com.alibaba.fastjson.JSON;
import csu.web.mypetstore.domain.Product;
import csu.web.mypetstore.service.CatalogService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "MouseOverShowServlet_2", urlPatterns = {"/mouseOver_2"})
public class MouseOverShowServlet_2 extends HttpServlet {
    private CatalogService catalogService;
    private static final String PRODUCT_FORM = "/WEB-INF/jsp/catalog/product.jsp";

    public MouseOverShowServlet_2(){
        catalogService = new CatalogService();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String productId = req.getParameter("productId");
        Product product = catalogService.getProduct(productId);
        String result = JSON.toJSONString(product);
        resp.setContentType("text/json");
        PrintWriter out = resp.getWriter();
        out.println(result);
    }
}
